package com.zzyl.nursing.controller.member;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.FamilyMemberElder;
import com.zzyl.nursing.dto.AddElderDto;
import com.zzyl.nursing.dto.HeartRateDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.MemberElderVo;
import com.zzyl.nursing.vo.health.HeartRateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IDeviceService deviceService;

    @Autowired
    private IDeviceDataService deviceDataService;
    /**
     * 解除绑定
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(Long id){
        familyMemberService.deleteById(id);
        return success();
    }

    /**
     * 按周统计查询指标数据
     * @param heartRateDto
     * @return
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public AjaxResult queryDeviceDataListByWeek(HeartRateDto heartRateDto){
        List<HeartRateVo> list = deviceDataService.queryDeviceDataListByWeek(heartRateDto);
        return success(list);
    }

    /**
     * 按天统计查询指标数据
     * @param heartRateDto
     * @return
     */
    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(HeartRateDto heartRateDto){
        List<HeartRateVo> list = deviceDataService.queryDeviceDataListByDay(heartRateDto);
        return success(list);
    }



    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家属")
    public AjaxResult addElder(@RequestBody AddElderDto addElderDto){
        familyMemberService.addElder(addElderDto);
        return success();
    }

    /**
     * 查询家人列表
     * @return
     */
    @GetMapping("/my")
    public AjaxResult page(){
        List<FamilyMemberElder> list = familyMemberService.selectPage();
        return success(list);
    }

    /**
     * 分页查询家人列表
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("list-by-page")
    public AjaxResult list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        List<MemberElderVo> list = familyMemberService.elderList(pageNum,pageSize);
        return success(list);
    }

    /**
     * 查询健康数据
     * @param request
     * @return
     */

    @PostMapping("/QueryDevicePropertyStatus")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request)
    {
        return deviceService.queryDevicePropertyStatus(request);
    }

}
